using System.Data.Common;

namespace Dapper.Extensions
{
	public static class Extensions
	{
		public static Dictionary<string, object> GetSqlParameters(this DbCommand command, bool hideValues = false)
		{
			IEnumerable<DbParameter> GetParameters()
			{
				foreach (DbParameter parameter in command.Parameters)
					yield return parameter;
			}

			return GetParameters()
				.ToDictionary(
					k => k.ParameterName,
					v => hideValues
						? "?"
						: v.Value == null || v.Value is DBNull
							? "<null>"
							: v.Value);
		}
	}
}
